<blockquote class="layui-elem-quote">
    <div class="layui-inline">
        <i class="layui-icon layui-icon-list layui-head-icon"></i>
        <span class="layui-font-16 layui-font-green">拼团商品管理</span>
    </div>
    <div class="layui-pull-right">
        <a class="layui-btn layui-btn-primary layui-border-green" id="option">复制主商城商品</a>
        <a class="layui-btn layui-btn-primary layui-border-green" href="{:url('/store/group/goods/create')}">添加拼团商品</a>
    </div>
</blockquote>
<div class="layui-card">
    <div class="layui-card-body">
        <fieldset class="layui-elem-field">
            <legend>条件搜索</legend>
            <div class="layui-field-box">
                <form class="layui-form layui-form-pane" action="{:url('/store/group/goods')}" method="GET">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">商品状态</label>
                            <div class="layui-input-inline">
                                <select name="status">
                                    <option value="">请选择状态</option>
                                    <option value="1">上架</option>
                                    <option value="0">下架</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">商品名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="keyword" placeholder="请输入商品名称" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <button class="layui-btn" lay-submit lay-filter="search">搜索</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <form class="layui-form">
            <table class="layui-table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>商品主图</th>
                    <th>商品名称</th>
                    <th>原价</th>
                    <th>销售价</th>
                    <th>拼团价</th>
                    <th>总库存</th>
                    <th>状态</th>
                    <th>创建时间</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>

                {foreach $list as $vo}
                <tr>
                    <td>{$vo.id}</td>
                    <td><img src="{$vo.main_image}" class="layui-view-img"></td>
                    <td>{$vo.goods_name}</td>
                    <td>{$vo.market_price}</td>
                    <td>{$vo.sell_price}</td>
                    <td>{$vo.group_price}</td>
                    <td>{$vo.stock}</td>
                    <td>
                        {empty name='$vo.status'}
                        <span class="layui-font-red">已下架</span>
                        {else/}
                        <span class="layui-font-green">已上架</span>
                        {/empty}
                    </td>
                    <td>{$vo.create_time}</td>
                    <td>{$vo.update_time}</td>
                    <td>
                        {empty name='$vo.status'}
                        <a class="layui-btn layui-btn-sm layui-btn-primary layui-border-green switch"
                           data-url="{:url('/store/group/goods/switch')}"
                           data-status="1"
                           data-id="{$vo.id}">上架</a>
                        {else/}
                        <a class="layui-btn layui-btn-sm layui-btn-primary layui-border-red switch"
                           data-url="{:url('/store/group/goods/switch')}" data-status="0" data-id="{$vo.id}">下架</a>
                        {/empty}
                        <a class="layui-btn layui-btn-sm"
                           href="{:url('/store/group/goods/edit',['id'=> $vo.id])}">编辑</a>
                        <a class="layui-btn layui-btn-sm layui-btn-danger del"
                           data-url="{:url('/store/group/goods/delete',['id'=> $vo.id])}">删除</a>
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
        </form>
        {$list|raw}
    </div>
</div>
<script>
    $('#option').click(function () {
        layer.open({
            title: ['选择商品'],
            type: 2,
            area: ['1000px', '800px'],
            offset: '30px',
            btn: ['确定', '取消'],
            maxmin: true,
            content: "{:url('/store/goods/option')}",
            yes: function (index, layero) {
                let id = $(layero).find('iframe').contents().find('input[type="radio"]:checked').val();
                if (!id) {
                    layer.msg('请选择商品!', {icon: 2});
                    return false;
                }
                let href = "{:url('/store/group/goods/create')}?id=" + id;
                location.href = href
            }
        });
    });
</script>
